package com.hup.joystick.presenter;

import com.hup.joystick.model.joystick.AutoConnectConfig;
import com.hup.joystick.mvp.FunctionSettingMvp.FunctionSettingPresenter;
import com.hup.joystick.mvp.MainMvp.MainPresenter;
import com.hup.joystick.service.joystick.AutoConnectListener;
import com.hup.joystick.service.joystick.JoystickService;
import com.hup.joystick.view.functionSetting.FunctionSettingFrame;
import com.hup.utils.commons.start.SpringContext;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * @author hugan
 * @date 2020/10/25
 */
@Log4j2
@Lazy
@Component
public class FunctionSettingPresenterImpl implements FunctionSettingPresenter {

    private final JoystickService joystickService;

    public FunctionSettingPresenterImpl(JoystickService joystickService) {
        this.joystickService = joystickService;
    }

    @Override
    public void onWindowClosing() {
        log.info("");
        joystickService.stopAutoConnect(true);
        SpringContext.getBean(MainPresenter.class).onWindowClosing(FunctionSettingFrame.class);
    }

    @Override
    public void startAutoConnect(AutoConnectListener autoConnectListener) {
        joystickService.startAutoConnect(new AutoConnectConfig(), autoConnectListener);
    }
}
